<html>
<head>
	<meta charset="utf-8">
	<title>Test</title>
	<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
	</script>
	<script>


        var url = '{$searchUrl}';
        var hotUrl = '{$hotUrl}';

        //检查是否有需要查询的商品ID
        function checkGoodsIds(){
            $.ajax({
                url:"",
                type: "POST",
                data: {},
                dataType:'json',
                async:false,
                success:function(res){
                    if(res.code && res.data.length > 0) {
                        res.data.forEach(function(item) {
                            searchGoods(item);
                        })
                    }

                }
            });
        }


        //检查优惠券生成
        function checkJdCoupon(){
            //检查是否有要生成优惠券的商品
            $.ajax({
                url: "{:url('task/searchJdCoupon')}",
                type: "POST",
                data: {},
                dataType:'json',
                async:false,
                success:function(res){
                    if(res.code && res.data.length > 0) {
                        //生成优惠券
                        res.data.forEach(function(item) {
                            $.ajax({
                                url:"https://media.jd.com/gotoadv/getCustomCodeURL",
                                type: "POST",
                                data: item,
                                dataType:'json',
                                async:false,
                                success:function(res){
                                    if(res.rspCode == 200) {
                                        item.longCouponUrl = res.data.longCouponUrl;
                                        item.longUrl = res.data.longUrl;
                                        item.qRcode = res.data.qRcode;
                                        item.shotCouponUrl = res.data.shotCouponUrl;
                                        item.shotUrl = res.data.shotUrl;
                                        //保存到redis
                                        $.ajax({
                                            url:"{:url('task/saveCouponUrl')}",
                                            type: "POST",
                                            data: item,
                                            dataType:'json',
                                            async:false,
                                            success:function(res){
                                                console.log(res)
                                            }
                                        });
                                    }
                                }
                            });
                        })
                    }

                }
            });
        }


        //查找商品信息及推广链接
        function searchGoods(keyword){
            $.ajax({
                url:url+keyword,
                type: "GET",
                success:function(result){
                    console.log(result);
                     $.ajax({
                        url:"{:url('task/pregGoods')}",
                        type: "POST",
                        data: {html: result, keyword: keyword},
                        dataType:'json',
                        async:false,
                        success:function(res){
                            console.log(res);
                            return;
                            if(res.code) {
                            var goodsData = res.data;
                                
                                
                            } 
                        }
                    });
                }

                
            });
        }

        //查找商品信息及推广链接
        function getHotGoods(){
            for (var i = 1; i < 3; i++) {
                var hotUrl = 'https://media.jd.com/gotoadv/goods?searchId=1000513924%23%23%23st3%23%23%23kt0%23%23%23a22470cc-9b86-46f1-8d29-c2caa42fd574&pageIndex='+i+'&pageSize=50&property=&sort=&goodsView=&adownerType=&pcRate=&wlRate=&category1=&category=&category3=&condition=1&fromPrice=&toPrice=&dataFlag=0&keyword=&input_keyword=&hasCoupon=1&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE&price=MOBILE';
                $.ajax({
                    url:hotUrl,
                    type: "GET",
                    success:function(result){
                        console.log(result);
                         $.ajax({
                            url:'{:url('task/pregGoods')}',
                            type: "POST",
                            data: {html: result},
                            dataType:'json',
                            async:false,
                            success:function(res){
                                if(res.code) {
                                var goodsData = res.data;
                                    res.data.forEach(function(item) {
                                        $.ajax({
                                            url:"https://media.jd.com/gotoadv/getCustomCodeURL",
                                            type: "POST",
                                            data: item,
                                            dataType:'json',
                                            async:false,
                                            success:function(res){
                                                if(res.rspCode == 200) {
                                                    item.longCouponUrl = res.data.longCouponUrl;
                                                    item.longUrl = res.data.longUrl;
                                                    item.qRcode = res.data.qRcode;
                                                    item.shotCouponUrl = res.data.shotCouponUrl;
                                                    item.shotUrl = res.data.shotUrl;
                                                    $.ajax({
                                                        url:"{:url('task/saveJbUrl')}",
                                                        type: "POST",
                                                        data: item,
                                                        dataType:'json',
                                                        async:false,
                                                        success:function(res){
                                                            console.log(res)
                                                        }
                                                    });
                                                }
                                            }
                                        });
                                    })
                                    
                                } 
                            }
                        });
                    }

                    
                });
            }           
        }




        function search(){
            var data = {
                cat2Id: null,
                cat3Id: null,
                categoryId: null,
                deliveryType: 0,
                fromCommissionRatio: null,
                fromPrice: null,
                hasCoupon: 0,
                isCare: 0,
                isHot: null,
                isPinGou: 0,
                isZY: 0,
                key: "手机",
                keywordType: "kt1",
                lock: 0,
                orientationFlag: 0,
                searchType: "st1",
                sort: null,
                sortName: null,
                toCommissionRatio: null,
                toPrice: null,
            }

            var postData = {
                data: data,
                pageNo: 1,
                pageSize: 60,
                searchUUID: "606c323193e34e188f97ffcb1365e9ba"
            }
            $.ajax({
                url:'https://union.jd.com/api/goods/search',
                type: "POST",
                headers: {
                    origin: 'https://union.jd.com'
                },
                beforeSend: function(request) {

                    // request.setRequestHeader(":authority", "union.jd.com");
                    request.setRequestHeader("Accept", "application/json, text/plain, */*");
                },
                dataType:'json',
                data:postData,
                async:false,
                success:function(res){
                    console.log(res);
                }
            })
        }
        search();

        // getHotGoods();
        // checkGoodsIds();
        // checkJdCoupon();

        // //检查新商品
        // setInterval(checkGoodsIds, 2000);

        // setInterval(checkJdCoupon, 2000);

        // //匹配推荐商品,两小时一次
        // setInterval(getHotGoods, 7200000);
	</script>
</head>
<body>

<button>Test</button>
</body>
</html>

couponLink: "https://coupon.m.jd.com/coupons/show.action?key=70912fe32a8043b6a7ad1845e7516669&roleId=17928049&to=https://h5.m.jd.com/dev/RLVegkgjdNJoM4Y1WsvAnKLD7Qw/index.html"
isPinGou: 0
isSmartGraphics: 0
materialId: 8447686
materialType: 1
needAutoVerifyPlan: []
planId: 1619713903
promotionId: 1715593489
promotionType: 1
promotionTypeId: 1587370057
receiveType: "cps"
requestId: "s_20190301_23352748"
wareUrl: "http://item.jd.com/8447686.html"

abParam: "v1"
abVersion: "elite"
couponDiscount: 49.5
couponLink: "https://coupon.m.jd.com/coupons/show.action?key=70912fe32a8043b6a7ad1845e7516669&roleId=17928049&to=https://h5.m.jd.com/dev/RLVegkgjdNJoM4Y1WsvAnKLD7Qw/index.html"
couponQuota: 198
couponRemainCnt: 99807
deliveryType: 1
finalPrice: 248.5
goodCommentsShare: 100
hasCoupon: 1
inOrderComm30Days: 488.98
inOrderCount30Days: 18
isCare: 0
isCommonPlan: 1
isLock: 0
isPinGou: 0
isZY: 1
materialUrl: "jfs/t20557/159/1416009728/277844/96dd9b19/5b6a6181Ndad279aa.jpg"
needAutoVerifyPlan: []
orientationFlag: 0
planId: 1619713903
requestId: "s_20190301_23352748"
shopId: 1000124388
shopName: "雀巢健康科学海外自营旗舰店"
skuId: 8447686
skuName: "雀巢佳膳适糖中老年平衡血糖营养品调节三高 糖尿病 高血糖 低糖孕妇营养粉（800g*1罐）"
vid: 1000124388
wlCommission: 37.28
wlCommissionRatio: 15
wlPrice: 298
